<%@page isELIgnored="false" import="java.net.*" %>
<%@taglib prefix="tiles" uri="struts-tiles" %>
<%@taglib prefix="html" uri="struts-html" %>
<%@taglib prefix="c" uri="jstl" %>
<%@taglib prefix="fn" uri="jstl-fn" %>
					
<%@page import="com.mastercard.assets.web.util.to.UserLogin"%><div id="bodyContent">
						<h1>Edit User</h1>

<c:set value="${fn:length(UserRoles)}" var="UserRolesLength" />
<c:set value="${fn:length(UserLevels)}" var="UserLevelsLength" />
<c:set value="${fn:length(UserCounts)}" var="UserCountsLength" />
<c:set value="${fn:length(UserRoles) - 1}" var="UserRolesLengthBeforeLastIndex" />
<c:set value="${fn:length(UserLevels) - 1}" var="UserLevelsLengthBeforeLastIndex" />
<c:set value="${fn:length(UserAgencia)}" var="UserAgenciaLength" />
<c:set value="${fn:length(UserGroupers)}" var="UserGroupersLength" />
						<center>
						<html:form action="/EditarUsuarioEditar" method="post">
						<html:hidden property="regId" />
						<html:hidden property="catalogoId" value="13"/>
						<html:hidden property="operation" value="3"/>
						<br/>
						
						<div class='errors'>
						<html:errors/>
						</div>
						
						<table class="TablaCatalogosNuevoTipoCuenta">
							<thead>
								<tr>
									<th>
										Edit User
									</td>
								</tr>
							</thead>
							<tr>
								<td>
									<br/>
									<table class='TablaCatalogosFields'>
										<tr>
											<td class='TDLabel'>
												Login: &nbsp;&nbsp;
											</td>
											<td class='TDField'>
												<html:text property="campo1" styleClass='TextField'  />
											</td>
										</tr>
										<tr>
											<td class='TDLabel'>
												Password: &nbsp;&nbsp;
											</td>
											<td class='TDField'>
												<html:password property="campo4" styleClass='TextField' readonly="true" />
											</td>
										</tr>
										<tr>
											<td class='TDLabel'>
												Name: &nbsp;&nbsp;
											</td>
											<td class='TDField'>
												<html:text property="campo3" styleClass='TextField' />
											</td>
										</tr>
										<tr>
											<td class='TDLabel'>
												Email: &nbsp;&nbsp;
											</td>
											<td class='TDField'>
												<html:text property="campo2" styleClass='TextField' />
											</td>
										</tr>
                                                                                <tr>
											<td class='TDLabel'>
												Country: &nbsp;&nbsp;
											</td>
											<td class='TDField'>
												<html:select property='campoInt1' >
<c:forEach items="${ActivePaises}" var="pais">
    <c:if test="${EditarUsuarioEditarForm.catalogoId ne pais.cvePais }">
        <html:option value='${pais.cvePais}' >${pais.nombre} - ${pais.codigo}</html:option>
    </c:if>
    <c:if test="${EditarUsuarioEditarForm.catalogoId eq pais.cvePais }">
        <option value='${pais.cvePais}' selected >${pais.nombre} - ${pais.codigo}</option>
    </c:if>
</c:forEach>						
                                                                                            </html:select>
											</td>
										</tr>
										<tr>
											<td colspan='2' class='TDButton'>
												<html:submit value='Update' styleClass="ButtonSubmit" />
											</td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
						</html:form>
						
						<div class='errors'>${UserLogin.messageError}</div>
						
						<table width="100%">
							<tr>
								<td width="30%">
									<h2>
										User roles
									</h2>
								</td>
								<td width="70%" align='right'>
									<a href='AgregarRolAUsuario.do?regId=${EditarUsuarioEditarForm.regId}'>
										<img alt="Agregar un rol al usuario" src="images/btnAdd.gif">
									</a>
								</td>
							</tr>
						</table>
						
<c:choose>
<c:when test="${UserRolesLength gt 0}">
						<table class="tabDatos">
							<thead>
								<tr>
									<th>Name</th>
									<th width='80px'>Operation</th>
								</tr>
							</thead>
<c:forEach items="${UserRoles}" var="rol">
							<tr>
								<td>${rol.nombre}</td>
								<td>
<c:choose>
<c:when test="${UserRolesLength > 1}">
									<table border='0' style="border: none ;">
										<tr>
											<td>
												<html:form action="BorrarRolDeUsuario.do" method="post">
												<html:hidden property="operation" value="2"/>
												<html:hidden property="catalogoId" value="13"/>
												<html:hidden property="campo1" value="${rol.nombre}"/>
												<html:hidden property="regId" value="${EditarUsuarioEditarForm.regId}"/>
												<html:hidden property="campoInt1" value="${rol.cveRole}"/>
												<input type='image' src='images/btnEliminar.gif' />
												</html:form>
											</td>
										</tr>
									</table>
</c:when>
<c:otherwise>
									&nbsp;
</c:otherwise>
</c:choose>
								</td>
							</tr>
</c:forEach>
						</table>
</c:when>
</c:choose>
						
						
						
						<div class='errors'>${UserLogin.messageError2}</div>
						
						<table width="100%">
							<tr>
								<td width="30%">
									<h2>
										User Levels
									</h2>
								</td>
								<td width="70%" align='right'>
									<a href='AgregarNivelAUsuario.do?regId=${EditarUsuarioEditarForm.regId}'>
										<img alt="Agregar un rol al usuario" src="images/btnAdd.gif">
									</a>
								</td>
							</tr>
						</table>
						
						
<c:choose>
<c:when test="${UserLevelsLength gt 0}">
						<div align='center' style='text-align: center; color: red; font-size: 12px;'>
							${UserLogin.messageError2}
						</div>
						<table class="tabDatos">
							<thead>
								<tr>
									<th>Name</th>
									<th>Description</th>
									<th>Role</th>
									<th width='80px'>Operation</th>
								</tr>
							</thead>
<c:forEach items="${UserLevels}" var="level">
							<tr>
								<td>${level.nombre}</td>
								<td>${level.descripcion}</td>
								<td>${level.tblRole.nombre}</td>
								<td>
									<table border='0' style="border: none ;">
										<tr>
											<td>
												<html:form action="BorrarNivelDeUsuario.do" method="post">
												<html:hidden property="operation" value="6"/>
												<html:hidden property="catalogoId" value="13"/>
												<html:hidden property="campo1" value="${level.nombre}"/>
												<html:hidden property="regId" value="${EditarUsuarioEditarForm.regId}"/>
												<html:hidden property="campoInt1" value="${level.cveNivel}"/>
												<input type='image' src='images/btnEliminar.gif' />
												</html:form>
											</td>
										</tr>
									</table>
								</td>
							</tr>
</c:forEach>
						</table>
</c:when>
</c:choose>
                                                                        
<c:if test="${UserAgenciaLength ne 0 }">
    <table width="100%">
							<tr>
								<td width="30%">
									<h2>
										User Agency
									</h2>
								</td>
								<td width="70%" align='right'>
                                                                    &nbsp;
								</td>
							</tr>
						</table>
    <table class="tabDatos">
							<thead>
								<tr>
									<th>Name</th>
									<th>Description</th>
									<th>Contact</th>
                                                                        <th width='80px'>Phone</th>
								</tr>
							</thead>
<c:forEach items="${UserAgencia}" var="agencia">
							<tr>
								<td>${agencia.nombre}</td>
								<td>${agencia.descripcion}</td>
								<td>${agencia.contacto}</td>
								<td>${agencia.telefono}</td>
							</tr>
</c:forEach>
						</table>    
</c:if>
						

<c:if test="${ShowCounts}">
						<div class='errors'>${UserLogin.messageError3}</div>
						
						<table width="100%">
							<tr>
								<td width="30%">
									<h2>
										User Accounts
									</h2>
								</td>
								<td width="70%" align='right'>
									<a href='AgregarCuentaAUsuario.do?regId=${EditarUsuarioEditarForm.regId}'>
										<img alt="Agregar una cuenta al usuario" src="images/btnAdd.gif">
									</a>
								</td>
							</tr>
						</table>
						
<c:choose>
<c:when test="${UserCountsLength gt 0}">
						<table class="tabDatos">
							<thead>
								<tr>
									<th>Name</th>
									<th>Description</th>
									<th>Account type</th>
									<th width='80px'>Operation</th>
								</tr>
							</thead>
<c:forEach items="${UserCounts}" var="count">
							<tr>
								<td>${count.nombre}</td>
								<td>${count.descripcion}</td>
								<td>${count.tblTipoCuenta.nombre}</td>
								<td>
									<table border='0' style="border: none ;">
										<tr>
											<td>
												<html:form action="BorrarCuentaDeUsuario.do" method="post">
												<html:hidden property="operation" value="6"/>
												<html:hidden property="catalogoId" value="13"/>
												<html:hidden property="campo1" value="${count.nombre}"/>
												<html:hidden property="regId" value="${EditarUsuarioEditarForm.regId}"/>
												<html:hidden property="campoInt1" value="${count.cveCuenta}"/>
												<input type='image' src='images/btnEliminar.gif' />
												</html:form>
											</td>
										</tr>
									</table>
								</td>
							</tr>
</c:forEach>
						</table>
</c:when>
</c:choose>
</c:if>
                                                
<c:if test="${ShowGroupers}">
						<div class='errors'>${UserLogin.messageError3}</div>
						
						<table width="100%">
							<tr>
								<td width="30%">
									<h2>
										User Aggregators
									</h2>
								</td>
								<td width="70%" align='right'>
									<a href='AgregarTipoCuentaAUsuario.do?regId=${EditarUsuarioEditarForm.regId}'>
										<img alt="Agregar una cuenta al usuario" src="images/btnAdd.gif">
									</a>
								</td>
							</tr>
						</table>
						
<c:choose>
<c:when test="${UserGroupersLength gt 0}">
						<table class="tabDatos">
							<thead>
								<tr>
									<th>Name</th>
									<th>Description</th>
<!--									<th>Tipo de Cuenta</th>-->
									<th width='80px'>Operation</th>
								</tr>
							</thead>
<c:forEach items="${UserGroupers}" var="grouper">
							<tr>
								<td>${grouper.nombre}</td>
								<td>${grouper.descripcion}</td>
<!--								<td>${count.tblTipoCuenta.nombre}</td>-->
								<td>
									<table border='0' style="border: none ;">
										<tr>
											<td>
												<html:form action="BorrarTipoCuentaDeUsuario.do" method="post">
												<html:hidden property="operation" value="6"/>
												<html:hidden property="catalogoId" value="13"/>
												<html:hidden property="campo1" value="${grouper.nombre}"/>
												<html:hidden property="regId" value="${EditarUsuarioEditarForm.regId}"/>
												<html:hidden property="campoInt1" value="${grouper.cveTipoCuenta}"/>
												<input type='image' src='images/btnEliminar.gif' />
												</html:form>
											</td>
										</tr>
									</table>
								</td>
							</tr>
</c:forEach>
						</table>
</c:when>
</c:choose>
</c:if>
						</center>
					</div>
					<div id="footContent"></div>
<%
// toma el userLogin
UserLogin user = ( UserLogin ) session.getAttribute( "UserLogin" ) ;

user.clearMessageError( ) ;
%>